from django import newforms as forms
import models
from google.appengine.ext.db import djangoforms

class GolferForm(djangoforms.ModelForm):
	short_name = forms.CharField(widget=forms.TextInput(attrs={'size':'4','maxlength':'3'})) 
	class Meta:
		model = models.Golfer
		exclude = ['outing_list']

class CourseForm(djangoforms.ModelForm):
	class Meta:
		model = models.Course


class CourseFormWithHoleCount(djangoforms.ModelForm):
	hole_count = forms.IntegerField() 
	class Meta:
		model = models.Course

class HoleForm(djangoforms.ModelForm):
	number = forms.IntegerField()
	par = forms.IntegerField()
	name = forms.CharField(max_length = 64)

	def __init__(self, course=None, number=-1, *args, **kwargs):
		self.course = course
		self.number = number
		super(HoleForm, self).__init__(*args, **kwargs)

	def save(self):
		hole = models.Choice(course = self.course, 
							name = self.clean_data['name'],
							number = self.clean_data['number'],
							par = self.clean_data['par'])
		hole.put()
